package com.hermes.biz.common.util.login;

import java.util.HashMap;
import java.util.Map;

import com.hermes.biz.common.model.user.UserDO;

public class UserInfoMapUtil {

	public volatile static UserInfoMapUtil userInfoMapUtil;
	
	private Map<String,Long> userMap;
	
	private UserInfoMapUtil(){
		userMap = new HashMap<String,Long>();
	}
	
	public static UserInfoMapUtil getUserInfoMapUtil(){
		if(userInfoMapUtil==null){
				synchronized(UserInfoMapUtil.class){
					if(userInfoMapUtil==null){
						userInfoMapUtil = new UserInfoMapUtil();
					}
				}
		}
		return userInfoMapUtil;
	}
	
	public long getIdNumInMap(String userName){
		Object result = userMap.get(userName);
		if(result!=null){
			return (Long) result;
		}
		return 0;
	}
	
	public boolean putUserInfoToMap(UserDO userDO){
		
		String username = userDO.getUserName();
		long userId = userDO.getUserId();
		userMap.put(username,userId);
		return true;
	}
	
}
